﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.mMall.Public
{
    public partial class mfTraveFoodList : msBsc.Cls.mbPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void initplace()
        {
            string parentsId = this.GetParamHtValue("parentsId");
            string countryId = this.GetParamHtValue("countryId");
            string cityId = this.GetParamHtValue("cityId");
            string destionId = this.GetParamHtValue("destionId");
            string isAll = this.GetParamHtValue("isAll");
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                if (ds == null || ds.Tables[0].Rows.Count < 0)
                {
                    return;
                }
                if (string.IsNullOrEmpty(countryId))
                {
                    countryId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 10000, "");
                this.ExecJScript(@"setCity(" + strJson + @",""country_select"",'" + countryId + "');");

                ds = cbcc.SelectCountryByParentId(countryId);
                if (ds == null || ds.Tables[0].Rows.Count < 0)
                {
                    return;
                }
                if (string.IsNullOrEmpty(cityId))
                {
                    cityId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 10000, "");
                this.ExecJScript(@"setCity(" + strJson + @",""city_select"",'" + cityId + "');");

                ds = cbcc.SelectCountryByParentId(cityId);
                if (ds == null || ds.Tables[0].Rows.Count < 0)
                {
                    return;
                }
                if (isAll.ToLower() == "true")
                {
                    DataRow dr = ds.Tables[0].NewRow();
                    dr["COUNTRY_CITY_ID"] = "";
                    dr["COUNTRY_CITY_NME"] = "全部";
                    ds.Tables[0].Rows.InsertAt(dr, 0);
                }
                if (string.IsNullOrEmpty(destionId))
                {
                    destionId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 10000, "");
                this.ExecJScript(@"setCity(" + strJson + @",""destion_select"",'" + destionId + "');");
                GetFoodList(destionId, cityId, countryId);
            }
        }

        private void GetFoodList(string destionId, string cityId, string countryId)
        {
            string pageRows = this.GetParamHtValue("pageRows");
            string pageNum = this.GetParamHtValue("pageNum");
            using (msBsc.AppLogic.DataAlc.CBizPushNiceFood niceFood = new AppLogic.DataAlc.CBizPushNiceFood())
            {
                int pRows = 16;
                int.TryParse(pageRows, out pRows);
                int pNum = 1;
                int.TryParse(pageNum, out pNum);
                DataSet ds = niceFood.GetNiceFoodForPageview(pRows, pNum, destionId, cityId, countryId);
                if (ds == null || ds.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 200, "");
                this.ExecJScript(@"$('#scenicNumber').text('(" + ds.Tables[0].Rows[0]["DATACOUNT"] + @")');var _html = $('#svc_list_tem_food').html();
                            laytpl(_html).render(" + strJson + @", function (render) {
                                $('#food_list').append(render);
                            });showNextPage('" + ds.Tables[0].Rows[0]["DATACOUNT"] + "')");
            }
        }
        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                initplace();
            }
        }
    }
}